package com.power.taskcenter.tasks.custom;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import com.power.taskcenter.anno.RegisterTask;
import com.power.taskcenter.service.IDynamicTaskLogsService;
import com.power.taskcenter.tasks.DyTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;

import static java.lang.Thread.sleep;


@Component
@Slf4j
public class TestOneDyTask implements DyTask {

    @Autowired
    private IDynamicTaskLogsService dynamicTaskLogsService;
    @RegisterTask(enable = true, override = false, name = "动态任务1", remark = "详细配置任务信息", cron = "0/20 * * * * ?", status = 1)
    @Override
    public void run() {

        TimeInterval timer = DateUtil.timer();
        //执行业务代码
        try{
            dynamicTaskLogsService.saveLogs("testOneDyTask",new Date());
            sleep(30);
        }catch (Exception e){

        }
        Long ll = timer.intervalRestart();
        dynamicTaskLogsService.saveLogs("testOneDyTask","动态任务1 详细配置任务信息 "+ll+" 毫秒");
        log.info("testOneDyTask 动态任务1 详细配置任务信息  "+ll+"  毫秒");
    }
}
